#include "kukaforcecontrolinstance.h"
#include "Backend/kukaforcecontrolbackend.h"
#include "Hmi/kukaforcecontrolhmi.h"

KUKAForceControlInstance::KUKAForceControlInstance(short Local_Remote){
    if(Local_Remote == REMOTEHMI){
        this->pViualKUKAHmi = new visualkukarobothmi(REMOTEHMI);
    }
    else if(Local_Remote == LOCALCONTOLLER) {
        this->pViualKUKABackend = new visualkukarobotbackend();
        this->pViualKUKAHmi = new visualkukarobothmi(LOCALCONTOLLER);
        RegisiterBackendtoHmi();
    }
}

KUKAForceControlInstance::~KUKAForceControlInstance(){
    if(this->pViualKUKABackend != nullptr) delete this->pViualKUKABackend;
}

void KUKAForceControlInstance::RegisiterBackendtoHmi(){
    this->pViualKUKAHmi->getBackendhandle(this->pViualKUKABackend);
}

QWidget* KUKAForceControlInstance::getUiHandle(){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi;
    }
    else{
        return nullptr;
    }
    return nullptr;
}

short KUKAForceControlInstance::task_kukaloop_KUKAProcess(){
    if(this->pViualKUKABackend != nullptr){
        this->pViualKUKABackend->KUKAProcess();
    }
    return 1;
}

short KUKAForceControlInstance::task_maininit_ForceSensorConnect(){
    if(this->pViualKUKABackend != nullptr){
        this->pViualKUKABackend->ForceSensorConnect();
        return NOERROR;
    }
    return UNDERTAKE;
}
short KUKAForceControlInstance::task_mainloop_ForceSensorLoopRun(){
    if(this->pViualKUKABackend != nullptr){
        this->pViualKUKABackend->ForceSensorLoopRun();
    }
    return 1;
}

short KUKAForceControlInstance::task_uifast_UiDataUpdate(){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi->UiDataUpdate();
    }
    else{
        return UNDERTAKE;
    }
    return 1;
}

short KUKAForceControlInstance::task_uifast_ForceScopeUpdate(){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi->ForceScopeUpdate();
    }
    else{
        return UNDERTAKE;
    }
    return 1;
}

short KUKAForceControlInstance::task_uifast_RobotScopeUpdate(){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi->RobotScopeUpdate();
    }
    else{
        return UNDERTAKE;
    }
    return 1;
}

void KUKAForceControlInstance::task_com_RemoteDataRecv(QByteArray Data){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi->RemoteDataRecv(Data);
    }
    else{
    }
}
void KUKAForceControlInstance::task_com_RemoteDataSend(QByteArray& Data){
    if(this->pViualKUKAHmi != nullptr){
        return this->pViualKUKAHmi->RemoteDataSend(Data);
    }
    else{
    }
}
